<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script>
      var obj = {
        name: "孙悟空",
        age: "18",
        gender: "男",
        sayName: function () {
          alert(this.name);
        },
      };
      var obj = {
        name: "猪八戒",
        age: "28",
        gender: "男",
        sayName: function () {
          alert(this.name);
        },
      };
      var obj = {
        name: "沙和尚",
        age: "38",
        gender: "男",
        sayName: function () {
          alert(this.name);
        },
      };
      /**
       * 使用工厂创建对象
       * 通过该方法可以大批量创建对象
       */
      function createPerson(name, age, gender) {
        // 创建一个新的对象
        var obj = new Object();
        // 向对象中添加属性
        (obj.name = name),
          (obj.age = age),
          (obj.gender = gender),
          (obj.sayName = function () {
            alert(this.name);
          });
        // 将新的对象返回
        return obj;
      }
      var obj2 = createPerson("猪八戒", "28", "男");
      var obj2 = createPerson("白骨精", "16", "女");
      var obj2 = createPerson("蜘蛛精", "18", "女");
      obj.sayName();
      /**
         *使用工厂方法创建的对象，使用的构造都是Object
           所以创建对象都是Object这个类型
            就导致我们无法区分多种不同类型的对象
         */

      /**
       * 用来创建狗的对象
       */
      function createDog(name, age) {
        var obj = new Object();
        (obj.name = name),
          (obj.age = age),
          (obj.sayHello = function () {
            alert("汪汪");
          });
      }
    </script>
  </head>
  <body></body>
</html>
